import sys

if sys.platform == 'win32':
    portc = 'COM4'
    from twisted.internet import win32eventreactor
    win32eventreactor.install()
else:
    print sys.platform
    portc = '/dev/ttyAMA0'

from twisted.python import log, usage
  
#import wingdbstub  
  
class Options(usage.Options):
    optParameters = [
        ['port', 'p',  portc, 'Device for display'], #'/dev/ttyAMA0'
        ['baudrate', 'b', '115200', 'Baudrate for display'],
        ['outfile', 'o', None, 'Logfile [default: sys.stdout]'],
    ]   

if __name__ == '__main__':
    from twisted.internet import reactor
    from eDIP43A_Driver import eDIP43A_Driver
    from eDIP43A_Factory import eDIP43A_Factory 
    

    o = Options()
    try:
        o.parseOptions()
    except usage.UsageError, errortext:
        print "%s: %s" % (sys.argv[0], errortext)
        print "%s: Try --help for usage details." % (sys.argv[0])
        raise SystemExit, 1


    logFile = sys.stdout
    if o.opts['outfile']:
        logFile = o.opts['outfile']
    log.startLogging(logFile)
    
    factory = eDIP43A_Factory(None, None)
    driver = eDIP43A_Driver(factory, o.opts['port'], reactor, baudrate=int(o.opts['baudrate']))
    
      
    log.msg("Starting the client")
    reactor.run()
 
